<%--
  Created by IntelliJ IDEA.
  User: 1
  Date: 2020/10/17
  Time: 10:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<html>
<head>
    <title>mysql</title>
</head>
<body>
    <h3>mysql</h3>
    <span>
        <h4>sql:setDataSource</h4>
        <sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost/mybatis"
            user="root" password="123456"/>


        <sql:query var="result" dataSource="${snapshot}" >
            SELECT * FROM student
        </sql:query>

        <table border="1" width="100%">
<tr>
<th>ID</th>
<th>Name</th>
<th>Sex</th>
<th>Spcialty</th>
    <th>grade</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.id}"/></td>
<td><c:out value="${row.name}"/></td>
<td><c:out value="${row.sex}"/></td>
    <td><c:out value="${row.specialty}"/></td>
<td><c:out value="${row.grade}"/></td>
</tr>
</c:forEach>
</table>
        <hr/>
        <c:set var="sid" value="3"  />
        <sql:update var="delStu" dataSource="${snapshot}">
            DELETE FROM student WHERE id = ?
            <sql:param value="${sid}" />
        </sql:update>
<sql:query var="result" dataSource="${snapshot}" >
    SELECT * FROM student
</sql:query>

        <table border="1" width="100%">
<tr>
<th>ID</th>
<th>Name</th>
<th>Sex</th>
<th>Spcialty</th>
    <th>grade</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.id}"/></td>
<td><c:out value="${row.name}"/></td>
<td><c:out value="${row.sex}"/></td>
    <td><c:out value="${row.specialty}"/></td>
<td><c:out value="${row.grade}"/></td>
</tr>
</c:forEach>
</table>

    </span>

    <sql:update dataSource="${snapshot}" var="count">
        INSERT INTO student (`name`,`sex`,`specialty`,`grade`) VALUES ('new name', '1','222','3');
    </sql:update>
    插入数据返回的东西:${count}

</body>
</html>
